import { fetchProducts, fetchProductById } from './mockData';

// 封装API服务
export const getProducts = async () => {
  try {
    const data = await fetchProducts();
    return data;
  } catch (error) {
    throw new Error('获取商品列表失败');
  }
};

export const getProductById = async (id) => {
  try {
    const data = await fetchProductById(id);
    if (!data) throw new Error('商品不存在');
    return data;
  } catch (error) {
    throw new Error('获取商品详情失败');
  }
};